package com.xiaoKe.zhonghzu.global.tool;
import android.text.TextUtils;
import com.xiaoKe.zhonghzu.global.base.BaseApplication;


/**
 * @ProjectName : app
 * @Author : Shijingna
 * @Time : 2022/12/26 1:43 下午
 * @Description : 文件描述
 */
public class ResourceTool {

    /**
     * color资源中 id 获取
     **/
    public static int resColor(int colorName) {
        return BaseApplication.instance.getResources().getColor(colorName);
    }

    /**
     * mipmap文件夹下的名称为ic_launcher的图片的id
     * mipmap资源id
     **/
    public static int resMipmap(String mipmapName) {
        return BaseApplication.instance.getResources().getIdentifier(mipmapName, "mipmap", BaseApplication.instance.getPackageName());
    }
    /**
     * Drawable文件夹下的名称为ic_launcher的图片的id
     * Drawable
     **/
    public static int resDrawable(String mipmapName) {
        int content = 0;
        if (TextUtils.isEmpty(mipmapName)){
            return content;
        }else {
            content = BaseApplication.instance.getResources().getIdentifier(mipmapName, "drawable", BaseApplication.instance.getPackageName());
            if (content==0){
                content =  0;
            }
        }
        return content ;

    }

    /**
     * 布局文件的id,比如：R.layout.activity_main
     * //布局资源id
     **/
    public static int resLayout(String layoutName) {
        return BaseApplication.instance.getResources().getIdentifier(layoutName, "layout", BaseApplication.instance.getPackageName());
    }

    /**
     * 资源文件转string
     **/
    public static String resItnToString(String string) {
        String content = "";
        if (TextUtils.isEmpty(string)){
            return content;
        }else {
            int resStr = BaseApplication.instance.getResources().getIdentifier(string, "string", BaseApplication.instance.getPackageName());
            if (resStr==0){
                content =  string;
            }else {
                content =   resString(resStr);
            }
        }
        return content ;
    }
    /**
     * 资源文件转string
     **/
    public static String resString(int string) {
        return BaseApplication.instance.getString(string);
    }



}
